草庐IT

Lua 数据类型

全部标签

go - 将类型转换为数组 - GO 语法

在下面的syntax_1中,array:=[...]float64{7.0,8.5,9.1}和syntax_2,typePeopleinterface{SayHello()ToString()}typeStudentstruct{Personuniversitystringcoursestring}typeDeveloperstruct{Personcompanystringplatformstring}funcmain(){alex:=Student{Person{"alex",21,"111-222-XXX"},"MIT","BSCS"}john:=Developer{Person

go - 如何循环直到 *ipconn.Read() 读取了所有发送给它的数据

我在go中使用*ipconn.Write方法发送一些数据,但似乎*ipconn.Read()一次只能读取20个字节这里是服务器发送数据ln,err:=net.Listen("tcp","localhost:8888")conn,err:=ln.Accept()tmp:=make([]byte,10000)tmp=[]byte("abcdefghijklmnopqrstuvwxyz")conn.Write(tmp)这里是客户端接收数据conn,err:=net.Dial("tcp","localhost:8888")data:=make([]byte,100000)conn.Read(d

go - 错误;不能将 imageName(类型 ImageName)用作 appendgo 中的 dao.ImageName 类型

我正在用Go重构服务器端逻辑,但出现无法解决的错误。・client:react/axios・api:golang/gin・web-server:nginx・db:mysql・container:docker・ci-tool:travis・deploy:awselasticbeanstalk服务.gofuncGetSingleArticleService(c*gin.Context,db*sql.DB)Article{article,rows:=dao.GetSingleArticleDao(c,db)forrows.Next(){imageName:=ImageName{}err:=r

json - 如何从 golang-map 中检索数据

我将我的json数据放在Unmarsha1上。我怎样才能检索像这样的数据log.Print(b["beat"]["name"])但是我怎样才能检索像这样的数据log.Print(b["beat"]["name"])-->获取数据失败我的代码如下:varbmap[string]interface{}data:=[]byte(`{"foo":1,"beat":{"@timestamp":"2016-10-27T12:02:00.352Z","name":"localhost.localdomain","version":"6.0.0-alpha1"}}`)err:=json.Unmarsh

json - 从 restful API 获取 POST 类型方法的响应

如何从POST方法获取json响应?目前我只能获取Status-401Unauthorized和StatusCode-401funcpostUrl(urlstring,byt[]byte)(*http.Response,error){tr:=&http.Transport{DisableCompression:true,}client:=&http.Client{Transport:tr,Timeout:10*time.Second}req,err:=http.NewRequest("POST",url,bytes.NewBuffer(byt))req.Header.Set("X-Cu

go - 类型声明的位置

我很好奇这种类型的结构声明t:=Person{"girlie",12}仅当其类型在同一文件中声明时才有效。下面是我的文件。文件st.go,在里面输入def结构体,在mainfunc中使用packagestructstypepersonstruct{ageintnameint}文件practice.go,主要功能:packagemainimport("fmt""structs/dir")funcmain(){varsdir.Persons.Name="She"s.Age=12>>t:=Person{"girlie",12}fmt.Println(s.Name)fmt.Println(t.

Golang 类型转换

我对我的项目有具体问题输入="3d6"我想将这个字符串的某些部分转换为整数。例如,我想像整数一样使用input[0]。我该怎么做? 最佳答案 这里有两个问题:如何将字符串转换为整数最直接的方法是Atoistrconv包中的(ASCII到整数)函数,它将接收一串数字字符并将它们强制转换为整数。如何从已知字符串模式中提取有意义的成分为了使用strconv.Atoi,我们需要自己输入数字字符。有很多方法可以对字符串进行slice和切block。您可以直接抓取第一个和最后一个字符-input[:1]和input[2:]是门票。您可以根据字符

Golang ...字符串类型参数函数

为什么我不能在函数中加入参数funcex(cstring,ex...string){exec.Command(c,ex)}获取错误不能使用args(type[]string)astypestring。为什么? 最佳答案 您可以在语句exec.Command(c,ex...)中使用:ex...而不仅仅是ex以下面为例:funcex(cstring,ex...string){exec.Command(c,ex...)} 关于Golang...字符串类型参数函数,我们在StackOverflo

go - 为什么 unmarshal 使 golang 中的对象类型发生变化

我想编写一个mockData方法,它可以接受多种类型的参数并根据其json数据返回相应的对象。代码如下:funcMockData(jsonPathstring,vinterface{})(interface{},error){varretinterface{}data,_:=ioutil.ReadFile(jsonPath)switchv.(type){caseReq:ret=Req{}fmt.Printf("\n===beforeUnmarshal==%T===\n",ret)err=json.Unmarshal(data,&ret)iferr!=nil{...}fmt.Printf

json - 将复杂的 JSON 解码为结构并访问数据( slice 的 slice )

一段时间以来,我一直在为这个问题而烦恼。我有一个JSON文件,它必须采用以下格式,我需要在Go中迭代并使用IF语句:[[{"configName":"customer"},{"config":[{"emailSubject":"Newcustomeradded"},{"text":"Hitest2"},{"text":"added2"}]}][{"configName":"customerAndUser"},{"config":[{"emailSubject":"Newcustomeradded"},{"text":"Hi,test1"},{"text":"added1"}]}]]我想